<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
	$("#update").click(function(){
		$("#action_form").attr("action", "<?=url('Online::Amazon/Update')?>");
		$("#action_form").attr("method", "post");
		$("#action_form").submit();
	});
	$(".detail").colorbox({width:"60%", height:"80%", iframe:true});
	$("#ajax_update").click(function(){
		var $shop_ids = $('#multiselect').val();
		$("#ajax_update").attr("disabled", true);
		$.ajax({
			url: "<?=url('Online::Amazon/Update')?>&shop_ids=" + $shop_ids,
			type: "get",
			dateType: "json",
			beforeSend:
				function(){
					$("#loading_img").html("<img src='<?=Q::ini('custom_system/base_url')?>img/loading.gif' />");
				},
			success:
				function()
				{
					$("#loading_img").html("");
				}
		});
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get" id="action_form">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>			
<table class="form_table">
<tr>
	<th>选择店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
			<?foreach ($shop_group as $k => $sg):?>
			<optgroup label="<?=$k?>">
			<?foreach ($sg as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id'])) echo "selected='selected'"?>><?=$s['name']?></option>
			<?endforeach;?>
			</optgroup>
			<?endforeach;?>
		</select>
	</td>
</tr>	
<tr>
	<th>时间范围</th>
	<td>	
		<input type="text" name="start_time" class="datepicker" value="<?=isset($_GET['start_time']) ? $_GET['start_time'] : ''?>" /> to
		<input type="text" name="end_time" class="datepicker" value="<?=isset($_GET['end_time']) ? $_GET['end_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th></th>
	<td><input type="button" class="button" value="更新数据" id="update"/></td>
	<td><input type="button" class="button" id="ajax_update" value="更新任务数据" /></td>
	<td><span id="loading_img"></span></td>
</tr>
</table>
</form>
</fieldset>
<?php $this->_endblock();?>